<!--MEDIA EDITOR-->

<div id="srvrserror-2" style="display: none;"></div>
<div id="logm" style="display: none;"></div>

<div class="grid" style="width: 100%; display: block;">

    <form action="javacsript:" method="post" name="mediaGallery" id="mediaGallery" style="margin-bottom: 3px;"> 

        <table width="100%" cellspacing="0" cellspacing="0" id="media_gallery_content_grid" class="data border" style="margin-top: 0; margin-bottom: 0;">

            <thead>
                <tr style="background-image: url(<?=$url?>assets/img/sort_row_bg.gif); background-repeat: repeat-x; background-position: 0 50% ;">
                    <th>Tip</th>
                    <th>Slika</th>
                    <th>Natpis</th>
                    <th>Glavna</th>
                    <th>Paragraf</th>
                    <th>Lijevo <br style="height: 13px;">[PRIKAZ SLIKE]</th>
                    <th>Sredina <br>[PRIKAZ SLIKE]</th>
                    <th>Desno <br>[PRIKAZ SLIKE]</th>
                    <th>Dodaj</th>
                    <th>Ukloni</th>
                </tr>    
            </thead>

            <tbody>

                <input type="hidden" name="artId" id="artId" value="<?if(isset($article[0])) echo $article[0]['article_id']?>" />

                <!--MEDIA EDIT MODE--> 
                <? 


                    /************************************************************* 
                    *  CHECK IF EDIT OR INSERT ART
                    *************************************************************/

                    if(isset($article[0])){

                        /************************************************************* 
                        *  ARTICLE EDIT MODE
                        *************************************************************/

                        $cnt = count($articlemedia);

                        for ($i=0; $i<$cnt; $i++){?>
                        <tr id="mg-img-<?=$i?>" class="tbleft">
                            <td class="logoHolder-<?=$i?>" style="text-align: center;">
                                <?
                                    switch ($articlemedia[$i]['media_type']){
                                        case 'img': ?> <img src="<?=$url;?>assets/img/img-logo.png" height="23" /> <? break; 
                                        case 'yt': ?> <img src="<?=$url;?>assets/img/yt-logo.png" height="23" /> <? break;
                                        case 'mp3': ?> <img src="<?=$url;?>assets/img/mp3-logo.png" height="23" /> <? break;
                                    }
                                ?>
                            </td>                                                          
                            <td class="imgHolder-<?=$i?>" style="vertical-align: middle; text-align:center;">  
                                <?
                                    switch ($articlemedia[$i]['media_type']){
                                        case 'img': ?><img src="<?=$url?>tempatt/<?=$articlemedia[$i]['media_filepath']?>" height="23"><? break;
                                        case 'yt':  ?><img src="http://img.youtube.com/vi/<?=$articlemedia[$i]['media_filepath']?>/0.jpg" height="23"><? break;
                                    }
                                ?>                            

                            </td>                                       
                            <input type="hidden" name="img[]" id="img-<?=$i?>" value="<?=$articlemedia[$i]['articlemedia_media_id']?>" class="emptyChecker" />
                            <td><input type="text" name="caption[]" id="caption-<?=$i?>" style="width: 190px;" value="<?=$articlemedia[$i]['articlemedia_caption']?>" /></td>
                            <td>
                                <? //echo $articlemedia[$i]['articlemedia_main_img']?>
                                <input type="checkbox" name="main_img[]" id="main_img-<?=$i?>" class="glavna" value="<?=$articlemedia[$i]['articlemedia_media_id']?>" <? if($articlemedia[$i]['articlemedia_main_img']==1) echo 'checked'; ?> /></td>
                            <td><input type="text" name="sort[]" id="sort-<?=$i?>" style="width: 80px;" value="<? if($articlemedia[$i]['articlemedia_sort']!=0){echo $articlemedia[$i]['articlemedia_sort'];}?>" /></td>
                            <td style="text-align: center;"><input type="radio" name="img_pos[]<?=$i?>" value="left" <? if($articlemedia[$i]['articlemedia_position']=='left') echo 'checked="checked"'; ?>></td>
                            <td style="text-align: center;"><input type="radio" name="img_pos[]<?=$i?>" value="center" <? if($articlemedia[$i]['articlemedia_position']=='center') echo 'checked="checked"'; ?>></td>
                            <td style="text-align: center;"><input type="radio" name="img_pos[]<?=$i?>" value="right" <? if($articlemedia[$i]['articlemedia_position']=='right') echo 'checked="checked"'; ?>></td>
                            <td style="text-align: center;"><a href="javascript:" id="<?=$i?>" class="addImage"> Promjeni</a> 

                                <?
                                    switch ($articlemedia[$i]['media_type']){
                                        case 'img': ?> <span class="removeSpace">|</span> <a href="javascript:" id="<?=$i?>" class="cropImage">Kropuj</a> <? break;
                                    }
                                ?>                                        

                            </td>
                            <td style="text-align: center;"><a href="javascript:" class="ukloniRed">Ukloni red</a></td>
                        </tr>

                        <!--END MEDIA INSERT MODE--> 
                        <?
                        global $mc_id;
                        $mc_id = $i;
                        }

                    }else{?>


                    <?

                        /************************************************************* 
                        *  ARTICLE INSERT MODE
                        *************************************************************/

                        for ($i=0; $i<5; $i++){?>

                        <!--MEDIA INSERT MODE-->
                        <tr id="mg-img-<?=$i?>">
                            <td class="logoHolder-<?=$i?>" style="text-align: center;">No media </td>                                            
                            <td class="imgHolder-<?=$i?>" style="vertical-align: middle; text-align: center;">No preview</td>                                       
                            <input type="hidden" name="img[]" id="img-<?=$i?>" value="" class="emptyChecker" />
                            <td><input type="text" name="caption[]" id="caption-<?=$i?>" style="width: 190px;" /></td>
                            <td><input type="checkbox" name="main_img[]" id="main_img-<?=$i?>" class="glavna" /></td>
                            <td><input type="text" name="sort[]" id="sort-<?=$i?>" style="width: 80px;" value="<?=$i+1?>" /></td>
                            <td style="text-align: center;"><input type="radio" name="img_pos[]<?=$i?>" value="left"></td>
                            <td style="text-align: center;"><input type="radio" name="img_pos[]<?=$i?>" checked="checked" value="center"></td>
                            <td style="text-align: center;"><input type="radio" name="img_pos[]<?=$i?>" value="right"></td>
                            <td style="text-align: center;"><a href="javascript:" id="<?=$i?>" class="addImage"> Dodaj mediju</a></td>
                            <td style="text-align: center;"><a href="javascript:" class="ukloniRed">Ukloni red</a></td>
                        </tr>
                        <!--END MEDIA INSERT MODE--> 
                        <?
                        global $mc_id;
                        $mc_id = $i;
                        }
                }?>
                <script>

                </script>
            </tbody>
        </table>

    </form>

    <span style="float: right;" >Broj karaktera <span class="char">(43)</span>: <span id="cntCharMedia" style="color: red;"></span></span>


    <div>
        <a href="javascript:" id="dodajRed">Dodaj red</a>
    </div>
</div>